// Agent basis in project massimEcomp
/* agent perceives an area that is a square with the size 17 with
   the agent in the center. Each agent is able to see 289 cells. */

/* Initial beliefs and rules */
/* BELIEFS */


/* RULES */



/* initial DESIRES */
!search_cows.


/* INTENTIONS (PLANS AND ACTIONS) */
+!find_pos : true
	<- .wait("+pos(_,_,_)").

+!search_cows : not pos(_,_,_)
	<- !find_pos;
	   !search_cows.

+!search_cows : pos(_,_,_)
  <- !move;
     !search_cows.

+!search_cows : pos(_,_,_) & cow(_,_,_)
  <- !goto_cow_position.

+!goto_cow_position : pos(_,_,_) & cow(_,Cx,Cy)
  <- +target(Cx,Cy);
     !move.
     
/*
+!move : pos(X,Y,_)
  <- .print("move random");
     br.poli.ecomp.sma.massim.action.RandomPos(X,Y,NewX,NewY);
     br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
     moveTo(Direction);
     .wait("+pos(_,_,_)");
     !move.

*/

+!move : pos(X,Y,_) & cow(_,Cx,Cy)
 <- .print("Searching cow");
 	br.poli.ecomp.sma.massim.action.FindDirection(X,Y,Cx,Cy,Direction);
 	moveTo(Direction);
 	!move.

+!move : pos(X,Y,_) & not cow(_,Cx,Cy)
  <- .print("Move north");
    br.poli.ecomp.sma.massim.action.ChooseDirection(X,Y,Direction);
    br.poli.ecomp.sma.massim.action.PrintPosition(X,Y);
  	moveTo(Direction);
   !move.

+!move : pos(X,Y,_) & target(Cx,Cy) & Cx \== X & Cy \== Y
  <- .print("move to target");
     br.poli.ecomp.sma.massim.action.FindPos(X,Y,Cx,Cy,NewX,NewY);
     br.poli.ecomp.sma.massim.action.FindDirection(X,Y,NewX,NewY,Direction);
     moveTo(Direction);
     !move.

+!move : pos(X,Y,_) & target(Cx,Cy) & Cx == X & Cy == Y
  <- .print("target");
     -target(Cx,Cy).

